//引入axios,配置请求头的根路径和请求拦截
import axios from 'axios'

//创建axios实例
const HTTP = axios.create({
    baseURL: 'http://127.0.0.1:8000/api/',
    timeout: 6000,
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    }

})

//请求拦截
HTTP.interceptors.request.use(config => {
    //设置请求头信息
    // let token = localStorage.getItem('token') || ''
    // let uuid = localStorage.getItem('uuid') || ''
    // const headersOption = {
    //     token,
    //     uuid
    // }
    // config.headers = Object.assign(config.headers, headersOption)
    return config
}, err => { console.log(err); })

//响应拦截
HTTP.interceptors.response.use(res => {
    return new Promise((resolve, reject) => {
        if (res.status === 200) {
            resolve(res.data)
        } else {
            reject(res)
        }
    })
}, err => {
    console.log(err);
})
export default HTTP